import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

class AtiWebview extends StatefulWidget {
  final String? urlStr;

  const AtiWebview({
    super.key,
    this.urlStr = 'https://www.baidu.com/index.html',
  });

  @override
  State<AtiWebview> createState() => _AtiWebviewState();
}

class _AtiWebviewState extends State<AtiWebview> {
  bool isLoading = true;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return InAppWebView(
      initialUrlRequest: URLRequest(
        url: WebUri(widget.urlStr!),
      ), // 使用 new initialUrl 参数
      onWebViewCreated: (InAppWebViewController controller) {
        // 获取控制器
      },
      onLoadStart: (controller, url) {
        setState(() {
          isLoading = true; // 开始加载时显示加载指示器
        });
      },
      onLoadStop: (controller, url) {
        setState(() {
          isLoading = false; // 加载完成后隐藏加载指示器
        });
      },
    );
  }
}
